import os

import allure
import pytest

from selenium import webdriver
from time import sleep

from selenium.webdriver.common.by import By
@allure.epic("规秘")
@allure.story("登录")
class TestCase(object):
    @allure.title("输入正确的用户名和错误的密码进行登录")
    @allure.description("预期结果:用户名或密码错误")
    def testLogin(self):
        self.driver = webdriver.Chrome()
        self.driver.get("http://10.215.56.131:8002/#/ai-home")
        self.driver.maximize_window()
        username = "test"
        password = "qweqw"
        expected = "用户名或密码错误"
        sleep(1)
        self.driver.find_element(By.XPATH,'//*[@id="guimi-home"]/body/section[1]/div/button/span').click()
        sleep(1)
        self.driver.find_element(By.XPATH,'//*[@id="pane-STANDARD"]/div/div[1]/div/div/input').clear()
        self.driver.find_element(By.XPATH,'//*[@id="pane-STANDARD"]/div/div[1]/div/div/input').send_keys(username)
        self.driver.find_element(By.XPATH,'//*[@id="pane-STANDARD"]/div/div[2]/div/div/input').clear()
        self.driver.find_element(By.XPATH,'//*[@id="pane-STANDARD"]/div/div[2]/div/div/input').send_keys(password)
        self.driver.find_element(By.XPATH,'//*[@id="pane-STANDARD"]/div/div[4]/button/span').click()
        sleep(2)
        actual = self.driver.find_element(By.XPATH,"/html/body/div[2]/p")
        text = actual.text
        assert text == expected
# if __name__ == '__main__':
#     #case = TestCase()
#     #case.login("test","123456","用户名或密码错误")
#     #pytest.main(["testlogin.py"])
#     # 1. 使用pytest生成测试报告时需要传递一个列表
#     json_dir_path = 'result'
#     args_list = ['-s', '-v', 'cases', '--alluredir', json_dir_path]
#     pytest.main(args_list)
#     # 2. 使用allure命令生成测试报告 ：allure generate 数据路径文件 -o html路径文件 -c
#     html_dir_path = 'report'
#     cmd = 'allure generate {} -o {} -c'.format(json_dir_path, html_dir_path)
#     os.system(cmd)

# 执行一下代码可以生成报告，点击报告中的index.html文件即可查看报告
if __name__ == '__main__':
    pytest.main(['testLoginAllure.py','--alluredir','./allure-results'])  #生成结果
    os.system('allure generate ./result -o ./allure-report --clean')  #将结果生成报告

# 控制台执行
# 首先cd对应的目录下 cd testcase  cd pytest
# 执行 pytest --alluredir=allure-results testLoginAllure.py 生成结果
# 生成报告 allure generate allure-results -o report --clean 生成报告
# 查看报告 allure serve 报告目录